﻿using Microsoft.SharePoint.Linq;
using ZhukBlogLinqExamples.Model.Meta;

namespace ZhukBlogLinqExamples.Model
{
    /// <summary>
    /// DataContext
    /// </summary>
    public class ZhukDataContext : DataContext
    {
        /// <summary>
        /// DataContext
        /// </summary>
        /// <param name="requestUrl">SharePoint site' URL</param>
        public ZhukDataContext(string requestUrl) :
            base(requestUrl)
        {
            Log = new ZhukBlogTracer();
        }

        /// <summary>
        /// Retrieving metadata for list
        /// </summary>
        /// <typeparam name="TEntity">Entity</typeparam>
        /// <param name="listName">List' name</param>
        /// <returns>Metadata</returns>
        public EntityListMetaData GetListMetaData<TEntity>(string listName) where TEntity : ZhukDataItem
        {
            return EntityListMetaData.GetMetaData(GetList<TEntity>(listName));
        }
    }
}
